﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Web;
using System.IO;
using Newtonsoft.Json;
using WCFServiceWebRole1.DataObjects;
using System.ServiceModel.Activation;
using GlobalObjects;


namespace WCFServiceWebRole1.Services
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "Idevice" in both code and config file together.
    [ServiceContract]
    public interface Idevice
    {
        // Post Request from Gadgeteer Library to register sensors associated with a device
        //Takes the JSON in the following format: 
        //{"APIKey":"sg8sdg8s8gs8gse8g8wg9wg9wr9","Device":{"Id":"11","Location":"Home","Name":"MyFridge","Userid":"10"},"Sensors":[{"deviceid":"10","id":"1","make":"GHI","name":"Sensor1","type":"TemperatureSensor"},{"deviceid":"10","id":"1","make":"GHI","name":"Sensor1","type":"TemperatureSensor"},{"deviceid":"10","id":"1","make":"GHI","name":"Sensor1","type":"TemperatureSensor"},{"deviceid":"10","id":"1","make":"GHI","name":"Sensor1","type":"TemperatureSensor"},{"deviceid":"10","id":"1","make":"GHI","name":"Sensor1","type":"TemperatureSensor"}]}
     

        #region Devices
        
        //Receive a changed ip address from a device
        [OperationContract]
        [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Bare,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "device/changeip?deviceid={deviceid}&ipaddress={ipaddress}")]
        string changeIpAddress(int deviceid, string ipaddress);

        //Receive the heartbeat message
        [OperationContract]
        [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Bare,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "heartbeat?deviceid={deviceid}")]
        string recordHearBeat(int deviceid);

        //Registering Device for first time
        [OperationContract]
        //    [FaultContract(typeof(DataContractSerializer))]
        [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare,
            // RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "device")]
        string deviceregister(DeviceRegistrationRequestDataContract rawJSON);

        #endregion

        #region Sensors

       

        //Add a Sensor
        //Takes json in this format:
        [OperationContract]
        [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare,
            RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "sensors")]
        string addSensor(Sensor sensor);

        //Update details of a sensor
        //Takes json in this format:
        [OperationContract]
        [WebInvoke(Method = "PUT", BodyStyle = WebMessageBodyStyle.Bare,
            RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "sensor/{sensorid}")]
        string updateSensor(string sensorid,Sensor sensor);

        // Get information about a sensor by Id
        [OperationContract]
        [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Bare,
            //RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "sensor/{sensorid}")]
        SensorResponse getSensorsById(string sensorid);

        //Remove a sensor
        //Returns boolean true if operation is successful 
        [OperationContract]
        [WebInvoke(Method = "DELETE", BodyStyle = WebMessageBodyStyle.Bare,
            RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "sensors/deviceid={deviceid}&sensorid={sensorid}")]
        bool deleteSensor(String deviceid, String sensorid);

        //Send measurement interval to device
        [OperationContract]
        [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare,
            RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "sensors/measureinterval?deviceid={deviceid}&sensorid={sensorid}&interval={interval}")]
        string measureInterval(int deviceid, int sensorid,int interval);

        #endregion








    }


}